
#include <iostream>
#include <cstdio>
#include <deque>
using namespace std;
#include <stdio.h>
deque<int> dq;

int main() {
	int n, m, a, i;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++)
		dq.push_back(i);
	while (1) {
		if (dq.size() == 1)
			break;
		for (i = 1; i < m; i++) {
			a = dq.front();
			dq.pop_front();
			dq.push_back(a);
		}
		dq.pop_front();
	}
	a = dq.front();
	printf("%d\n", a);
	return 0;
}